<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/include/tagLib.jsp" %>
<!doctype html>
<html lang="en">
<head>
    <title>${sieName}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <%@include file="/include/cssLib.jsp" %>
</head>

<body>
    <%@include file="/include/normalHead.jsp" %>
    <div class="wrapper wrapper-full-page">
        <div class="full-page login-page" filter-color="black" data-image="${ctxStatic}/img/login.jpg">
            <!--   you can change the color of the filter page using: data-color="blue | purple | green | orange | red | rose " -->
            <div class="content">
                <div class="container">
                    <div class="row">
                        <div class="col-md-4 col-sm-6 col-md-offset-4 col-sm-offset-3">
                            <form id="loginForm" method="post" action="#" onsubmit="return submitFun();">
                                <div class="card card-login card-hidden">
                                    <div class="card-header text-center">
                                        <h4 class="card-title">密码登录</h4>
                                        <%--
                                        <c:if test="${not empty oauthList}">
                                            <div class="social-line">
                                               <c:forEach items="${oauthList}" var="oauth">
                                                    <a href="javascript:;" onclick="loginByOAuth(${oauth.appId})" title="第三方登录：${oauth.siteName}" class="btn btn-oauth-img">
                                                        <img src="${ctxStaticImg}/oauth/${oauth.icon}">
                                                    </a>
                                                </c:forEach>
                                            </div>
                                        </c:if>
                                        --%>
                                    </div>
                                    <p class="category text-center"></p>
                                    <div class="card-content">
                                        <div class="input-group">
                                            <span class="input-group-addon">
                                                <i class="material-icons">phone</i>
                                            </span>
                                            <div class="form-group label-floating">
                                                <label class="control-label">手机号码</label>
                                                <input class="form-control" id="userPhone" name="phone" type="number" required="true" value="13632676703" minlength="11" maxlength="11" max="99999999999" />
                                            </div>
                                        </div>
                                        <div class="input-group">
                                            <span class="input-group-addon">
                                                <i class="material-icons">lock_outline</i>
                                            </span>
                                            <div class="form-group label-floating">
                                                <label class="control-label">密码</label>
                                                <input class="form-control" id="userPwd"  name="password" type="password" required="true" value="111111" />
                                            </div>
                                        </div>
                                    </div>
                                    <div class="footer text-center">
                                        <button type="submit" class="btn btn-twitter btn-wd">立即登录</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <%@include file="/include/footer.jsp" %>
        </div>
    </div>
</body>

</body>
<%@include file="/include/scriptLib.jsp" %>
<%@include file="/include/validScriptLib.jsp" %>
<script src="${ctxStatic }/js/jsencrypt.min.js"></script>
<script type="text/javascript">

    //获取public key
    var publicKey = null;
    setTimeout(function() {
        HttpUtil.ajaxAsyncJsonPost("/adminConsole/login/getPubKey", {}, function(pubKey){
            publicKey = pubKey;
        });
    }, 1000);


    $().ready(function() {
        setFormValidation('#loginForm');
        demo.checkFullPageBackgroundImage();
        setTimeout(function() {
            $('.card').removeClass('card-hidden');
        }, 700);
        
    });

    function submitFun(){
        var form = $("#loginForm");
        if(!form. valid()){
            return false;
        }

        var userPhone = $("#userPhone").val();
        var userPwd = $("#userPwd").val();
        //进行加密
        var encrypt = new JSEncrypt();
        if(publicKey != null){
            encrypt.setPublicKey(publicKey);
            userPhone = encrypt.encrypt(userPhone);
            userPwd = encrypt.encrypt(userPwd);
        }
        HttpUtil.ajaxAsyncJsonPost("/adminConsole/login/in", {phone: userPhone, sigPwd: userPwd}, function(message){
            dialogTip(message);
            setTimeout(function() {
                if(window.location.pathname.startWith(ctx+"/adminConsole/login")){
                    window.location.href = ctx+"/adminConsole/page/index";
                }else{
                    refreshPage();
                }
            }, 500);
        });
        return false;
    }

    function loginByOAuth(appId){
        dialogPrompt("第三方登录-认证手机号", "请输入手机号", function(data){
            dialogTip("号码认证中...");
            HttpUtil.ajaxAsyncJsonPost("/adminConsole/login/oauth", {appId: appId, phone: data}, function(message){
                dialogTip(message);
                setTimeout(function() {
                    window.location.href = ctx+"/adminConsole/page/index";
                }, 500);
            });
        }, 'tel');
        return false;
    }
</script>

</html>